﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using MyWCF.Demo.Contracts.Calculator;
using MyWCF.Demo.Client.ConsoleApp.CalculatorServices;
using System.ServiceModel.Channels;

namespace MyWCF.Demo.Client.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (CalculatorClient calculatorClient = new CalculatorClient())
            {
                //有报头的代码实现方式
                //using (OperationContextScope contextScope = new OperationContextScope(calculatorClient.InnerChannel as IClientChannel))
                //{
                //    AddressHeader addressHeader = AddressHeader.CreateAddressHeader("", "", "");
                //    OperationContext.Current.OutgoingMessageHeaders.Add(addressHeader.ToMessageHeader());
                //    calculatorClient.CalculatorAdd(2,3);
                //}
                Console.WriteLine("x+y=" + calculatorClient.CalculatorAdd(5, 6));
            }
            using (ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>("CalculatorServiceClient"))
            {
                ICalculator proxy = channelFactory.CreateChannel();
                using (proxy as IDisposable)
                {
                    //using (OperationContextScope contextScope = new OperationContextScope(proxy as IClientChannel))
                    //{
                    //    MessageHeader<string> messageHeader = new MessageHeader<string>("");
                    //    OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader.GetUntypedHeader("", ""));
                    //    proxy.Add(1, 4);
                    //}
                    Console.Write(proxy.Add(3, 4));
                }
            }
            Console.Read();
        }
    }
}
